package com.example.a2018.myapplication;

import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.Exception.ConnectException;
import com.Exception.startIPCameraException;
import com.Exception.tutkAPIException;
import com.liwenxu.Connect;
import com.liwenxu.MySurfaceView;
import com.liwenxu.VideoPlay;

/**
 * Created by Li Peicheng on 2018/9
 */
public class FullScreenActivity extends MainActivity {



    private Spinner spinner;
    private String[] clarity={"超清","高清","标清","流畅"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
                WindowManager.LayoutParams. FLAG_FULLSCREEN);
        setContentView(R.layout.fullscreen);

        jump(R.id.back,EquipmentActivity.class);
        spinner = (Spinner)findViewById(R.id.spinner_vedio);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }

        });
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,clarity);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);




            MySurfaceView mySurfaceView=new MySurfaceView(this);
            mySurfaceView.setLayoutParams(new ViewGroup.LayoutParams(640, 368));
            FrameLayout preview = (FrameLayout) findViewById(R.id.FL2);
            preview.addView(mySurfaceView);
            try {
                Connect.getChannelId("admin", "123456", 0);

            } catch (ConnectException e){
                Toast.makeText(this,"发现错误:"+e.getMessage(),Toast.LENGTH_SHORT);
            }
            try{
                VideoPlay videoPlay=new VideoPlay(this,mySurfaceView.getHolder());
                videoPlay.StartVideo(0);
            }
            catch (ConnectException e){
                Toast.makeText(this,"发现错误:"+e.getMessage(),Toast.LENGTH_SHORT);
            }
            catch (startIPCameraException e){
                Toast.makeText(this,"发现错误:"+e.getMessage(),Toast.LENGTH_SHORT);
            }
            catch (tutkAPIException e){
                Toast.makeText(this,"发现错误:"+e.getMessage(),Toast.LENGTH_SHORT);
            }

            //尚未更新stopvideo

            FrameLayout fl = (FrameLayout)findViewById(R.id.FL1);
            final LinearLayout l1 = (LinearLayout)findViewById(R.id.LL1);
            final LinearLayout  l2=(LinearLayout) findViewById(R.id.LL2);

            l1.setVisibility(ViewGroup.VISIBLE);
            l2.setVisibility(ViewGroup.VISIBLE);

            preview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(l2.getVisibility()==ViewGroup.VISIBLE) {
                        l2.setVisibility(ViewGroup.INVISIBLE);
                        l1.setVisibility(ViewGroup.INVISIBLE);
                    }
                    else if(l2.getVisibility()==ViewGroup.INVISIBLE){
                        l2.setVisibility(ViewGroup.VISIBLE);
                        l1.setVisibility(ViewGroup.VISIBLE);
                    }
                }

            });










    }





}
